//
//  MineStoreChooseCityViewController.m
//  renmingongshe
//
//  Created by macbook on 2017/11/7.
//  Copyright © 2017年 xiaodian. All rights reserved.
//

#import "MineStoreChooseCityViewController.h"

@interface MineStoreChooseCityViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_table;
}
@end

@implementation MineStoreChooseCityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLabel.text = @"选择区域";
    
    [self createTable];
}

- (void)createTable
{
    _table = [[UITableView alloc]initWithFrame:CGRectMake(0, 70, WIDTH, HEIGHT-70) style:UITableViewStylePlain];
    _table.delegate = self;
    _table.dataSource = self;
    [self.view addSubview:_table];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *di = _data[indexPath.section][@"list"][indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"aaa"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"aaa"];
    }
    cell.textLabel.text = di[@"areaName"];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.textLabel.textColor = [UIColor grayColor];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *a = _data[section][@"list"];
    return a.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *la= [[UILabel alloc]initWithFrame:CGRectMake(10, 10, WIDTH-20, 30)];
    [view addSubview:la];
    la.font = [UIFont boldSystemFontOfSize:16];
    la.text =_data[section][@"areaName"];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 49, WIDTH, 1)];
    [view addSubview:line];
    line.backgroundColor = [UIColor colorWithHex:0xf2f2f2];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *di = _data[indexPath.section][@"list"][indexPath.row];
    NSString *str = [NSString stringWithFormat:@"3_%@_%@_",_data[indexPath.section][@"areaId"],di[@"areaId"]];
    NSString *area = [NSString stringWithFormat:@"%@%@",_data[indexPath.section][@"areaName"],di[@"areaName"]];
    self.backType(area,str,di[@"areaId"]);
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
